<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增出库管理')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-fOutbound-add" th:object="${enter}">
            <input name="thingId" type="hidden" id="treeId" th:field="*{thingId}"/>
            <input id="enterInfo" name="enterInfo" type="hidden" th:value="${enterInfo}"/>
            <input name="thingTypeId" type="hidden" th:field="*{thingTypeId}"/>
            <input name="averageSunhao" type="hidden" id="averageSunhao"/>
            <div class="form-group">
                <label class="col-sm-3 control-label ">物品目录：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input readonly="readonly"  name="thingName"  type="text" th:field="*{thingName}" class="form-control">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                    <span style="color: red" id="kucuntishi"></span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">物品名称：</label>
                <div class="col-sm-8">
                    <input readonly name="createName" class="form-control" type="text" th:field="*{createName}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">物品信息：</label>
                <div class="col-sm-8">
                    <input readonly name="mohu" class="form-control" type="text" th:field="*{mohu}">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">收支项目：</label>
                <div class="col-sm-8">
                    <input readonly name="thingType" class="form-control" type="text" th:field="*{thingType}">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">最小度量物品数量：</label>
                <div class="col-sm-8">
                    <input id="shuliang" oninput="jisuan()" required name="shuliang" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">人均消耗：</label>
                <div class="col-sm-8">
                    <input id="pingjunSunhao" readonly="readonly" name="pingjunSunhao" class="form-control" type="number" >
                </div>
            </div>
<!--            <div class="form-group">-->
<!--                <label class="col-sm-3 control-label is-required">出库时间：</label>-->
<!--                <div class="date col-sm-8">-->
<!--                    <input name="outTime" type="text" class="form-control" id="outTime" placeholder="yyyy-MM-dd" required>-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">领用人：</label>
                <div class="col-sm-8">
                    <input id="recipientBy" name="recipientBy" class="form-control" type="text" >
                </div>
            </div>
<!--            <div class="form-group">-->
<!--                <label class="col-sm-3 control-label">出库类型：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <select name="outboundType" class="form-control m-b" th:with="type=${@dict.getType('f_outbound_type')}">-->
<!--                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>-->
<!--                    </select>-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var peopleNumber = [[${peopleNumber}]]
        var kuncunSize = [[${kuncunSize}]]
        $("#kucuntishi").html("最小度量物品数量 "+kuncunSize)

        if(!peopleNumber){
            $.modal.alertWarning('请填写所在行人数！')
        }
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            laydate.render({
                elem: '#outTime'
            });
        });

        var prefix = ctx + "financial/fOutbound"
        $("#form-fOutbound-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if(!peopleNumber){
                $.modal.alertWarning('请填写所在行人数！')
                return
            }

            if(parseInt(kuncunSize) < parseInt($("#shuliang").val())){
                $.modal.alertWarning('库存不足！')
                return
            }

            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-fOutbound-add').serialize());
            }
        }

        function selectThingTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "0" : $("#treeId").val();
            var url = ctx + "financial/fThing/selectFThingTree/" + deptId;
            var options = {
                title: '选择物品',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }
        function doSubmit(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            $.modal.close(index);
        }

        function wupin() {
            $("#averageSunhao").val("")
            $("#tishi").html("")
            $("#danwei").html("")

            $.ajax({
                url: prefix+'/selectAverageSunhao/'+ $("#treeId").val()+"/"+$("#thingType").val(),
                type: 'GET',
                success: function(res) {
                    console.log(JSON.stringify(res))
                    if(res.code==0){
                        if(res.data.sunhao != ""){
                            $("#tishi").html("平均消耗"+res.data.sunhao)
                            $("#averageSunhao").val(res.data.sunhao)
                        }
                        if(res.data.thingUnit != ""){
                            $("#danwei").html("/"+res.data.thingUnit)
                        }
                    }
                },
                error: function() {

                }
            });
        }

        function jisuan() {
            if(!peopleNumber){
               return
            }
            var num = $("#shuliang").val()/peopleNumber
            $("#pingjunSunhao").val(num.toFixed(2))
        }

        function thingTypeChange() {
            if($("#treeId").val()){

            }
        }

    </script>
</body>
</html>